package com.rongc.client.freight.business.mine.view.popup;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.rongc.client.core.utils.KeyboardUtil;
import com.rongc.client.core.utils.SystemUtil;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.view.widget.SpaceItemDecoration;
import com.rongc.client.freight.business.mine.view.adapter.RecyclerKeyboardAdapter;

/**
 * Created by Bruce on 2017/7/7.
 */
public class MinePopup {

    /**
     * 支付
     * @param context
     * @param mListener
     * @return
     */
    public static PopupWindow makePopupPayOption(Activity context ,
                                                 View.OnClickListener mListener) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View vPopupWindow = inflater.inflate(
                R.layout.popup_chongzhi, null, false);

        vPopupWindow.findViewById(R.id.lyt_way).setOnClickListener(mListener);
        vPopupWindow.findViewById(R.id.iv_close).setOnClickListener(mListener);
        vPopupWindow.findViewById(R.id.btn_pay).setOnClickListener(mListener);

        PopupWindow pw = new PopupWindow(vPopupWindow, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ,true);
        pw.setContentView(vPopupWindow);
		pw.setAnimationStyle(R.style.PopupAnimation);
        pw.setFocusable(true);
		/*设置背景显示*/
        ColorDrawable dw = new ColorDrawable(0xffffffff);
        pw.setBackgroundDrawable(dw);
        pw.update();
//	    设置触摸外面时消失
        pw.setOutsideTouchable(true);
        pw.setTouchable(true);


        return pw;
    }

    /**
     * 提现
     * @param context
     * @param mListener
     * @return
     */
    public static PopupWindow makePopupPayTxOption(Activity context , RecyclerKeyboardAdapter mAdapter,
                                                 View.OnClickListener mListener,KeyboardUtil.KeyBoardListener boardListener) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View vPopupWindow = inflater.inflate(
                R.layout.popup_tixian, null, false);

        vPopupWindow.findViewById(R.id.iv_close).setOnClickListener(mListener);
        vPopupWindow.findViewById(R.id.tv_forget).setOnClickListener(mListener);


        RecyclerView recyclerView = (RecyclerView) vPopupWindow.findViewById(R.id.recycler);
        GridLayoutManager mGridLayoutManager = new GridLayoutManager(context,6);
        recyclerView.addItemDecoration(new SpaceItemDecoration(SystemUtil.dip2px(context,4f)));
        recyclerView.setLayoutManager(mGridLayoutManager);
        recyclerView.setAdapter(mAdapter);

        KeyboardUtil keyboard = new KeyboardUtil(vPopupWindow, context, mAdapter.getDatas());
        keyboard.setListener(boardListener);


        PopupWindow pw = new PopupWindow(vPopupWindow, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ,true);
        pw.setContentView(vPopupWindow);
        pw.setAnimationStyle(R.style.PopupAnimation);
        pw.setFocusable(true);
		/*设置背景显示*/
        ColorDrawable dw = new ColorDrawable(0xffffffff);
        pw.setBackgroundDrawable(dw);
        pw.update();
//	    设置触摸外面时消失
        pw.setOutsideTouchable(true);
        pw.setTouchable(true);


        return pw;
    }

}
